var app = angular.module('junlebao.controllers', [])

	.controller("initCtrl", function($scope, $location, $rootScope) {

		$rootScope.isLogin = function() {
			var currentUser = AV.User.current();
			if(currentUser) {
				$rootScope.currentUser = currentUser;
				$rootScope.user = currentUser;
			} else {
				//currentUser 为空时，可打开用户登录界面;
				location.href = "#/login"
			}
		}
		$rootScope.getShopList = function() {

			var shopQuery = new AV.Query(Shop);
			shopQuery.find().then(function(shops) {

				$rootScope.areashop = [];
				for(var i = 0; i < shops.length; i++) {
					var shop = shops[i].attributes;
					var dd = {};
					dd.dname = shop.name;
					dd.dadress = shop.adress;
					dd.phone = shop.phone;
					dd.id = shops[i].id;
					$rootScope.areashop.push(dd);
				}
				$rootScope.shops2 = $rootScope.areashop;

				$rootScope.areashop = [];
				for(var i = 0; i < shops.length; i++) {
					var shop = shops[i].attributes;
					if(shop.area == $scope.user.attributes.userarea) {
						var dd = {};
						dd.dname = shop.name;
						dd.dadress = shop.adress;
						dd.phone = shop.phone;
						$rootScope.areashop.push(dd);
					}
				}

				$rootScope.shops = $rootScope.areashop;
			});
		}
		$rootScope.getPartners = function() {

			var order3Query = new AV.Query(Order);
			order3Query.descending('createdAt');
			order3Query.include('shop_id'); // 关键代码，用 include 告知服务端需要返回的关联属性对应的对象的详细信息，而不仅仅是 objectId
			order3Query.include('c_id'); // 关键代码，同上，会返回 targetAVUser 对应的对象的详细信息，而不仅仅是 objectId
			order3Query.include('c_id.user_id');
			order3Query.include('c_id.p_id');
			order3Query.equalTo('user_id', $rootScope.user);
			var d = new Date();
			var a = d.getFullYear();
			order3Query.equalTo('orderyear', a);
			var b = d.getMonth() + 1;
			order3Query.equalTo('ordermonth', b);
			$scope.sumorder = {};
			$scope.sumorder.sum = 0;
			$scope.sumorder.date_list = [];
			$scope.sumorder.year = a;
			$scope.sumorder.month = b;
			order3Query.find().then(function(orders) {
				$scope.sumorder.sum = 0;
				$scope.mid_list = [];
				$scope.sumorder.date_list = [];
				// comments 是最近的十条评论, 其 targetTodoFolder 字段也有相应数据
				for(var i = 0; i < 31; i++) {
					var dd = {};
					dd.date = i + 1;
					dd.money = 0;
					$scope.mid_list.push(dd);
				}
				for(var i = 0; i < orders.length; i++) {
					var order = orders[i];
					// 并不需要网络访问
					var shop = order.get('shop_id');
					var cProduct = order.get('c_id');
					var product = cProduct.get('p_id');
					var user = cProduct.get('user_id');
					$scope.sumorder.sum += order.attributes.onum * (order.attributes.c_id.attributes.price - order.attributes.discount);
					$scope.mid_list[order.attributes.orderday - 1].money += order.attributes.onum * (order.attributes.c_id.attributes.price - order.attributes.discount);
				}
				for(var i = 0; i < $scope.mid_list.length; i++) {
					if($scope.mid_list[i].money != 0) {
						var dd = {};
						dd.date = i + 1;
						dd.money = $scope.mid_list[i].money;
						$scope.sumorder.date_list.push(dd);
					}
				}

			}, function(error) {});
		}

		$rootScope.getPUser = function() {

			var userQuery = new AV.Query("PUser");
			//			userQuery.equalTo('boss', 0);
			userQuery.find().then(function(users) {
				var uu = {
					attributes: {
						user_id: "0",
						username: "全部"
					}
				};
				$rootScope.pusers = users;
				$rootScope.pusers.push(uu);
			});
		}
		$rootScope.getPartners2 = function(user_id) {

			var order2Query = new AV.Query(Order);
			order2Query.descending('createdAt');
			order2Query.include('shop_id'); // 关键代码，用 include 告知服务端需要返回的关联属性对应的对象的详细信息，而不仅仅是 objectId
			order2Query.include('c_id'); // 关键代码，同上，会返回 targetAVUser 对应的对象的详细信息，而不仅仅是 objectId
			order2Query.include('c_id.user_id');
			order2Query.include('c_id.p_id');
			var d = new Date();
			var a = d.getFullYear();
			order2Query.equalTo('orderyear', a);
			var b = d.getMonth() + 1;
			order2Query.equalTo('ordermonth', b);
			if(user_id != "0") {
				var todoFolder = AV.Object.createWithoutData("_User", user_id);
				order2Query.equalTo('user_id', todoFolder);
				//				alert("设置user_id："+user_id);
			}
			$rootScope.sumorder2 = {};
			$rootScope.sumorder2.sum = 0;
			$rootScope.sumorder2.date_list = [];
			$rootScope.sumorder2.year = a;
			$rootScope.sumorder2.month = b;

			order2Query.find().then(function(orders2) {

				$rootScope.sumorder2.sum = 0;
				$rootScope.mid_list2 = [];
				$rootScope.sumorder2.date_list = [];
				// comments 是最近的十条评论, 其 targetTodoFolder 字段也有相应数据
				for(var i = 0; i < 31; i++) {
					var dd = {};
					dd.date = i + 1;
					dd.money = 0;
					$rootScope.mid_list2.push(dd);
				}
				for(var i = 0; i < orders2.length; i++) {
					var order2 = orders2[i];
					// 并不需要网络访问
					//					console.log(order2);
					//					console.log(order2.attributes.onum * (order2.attributes.c_id.attributes.price - order2.attributes.discount));
					$rootScope.sumorder2.sum += order2.attributes.onum * (order2.attributes.c_id.attributes.price - order2.attributes.discount);
					$rootScope.mid_list2[order2.attributes.orderday - 1].money += order2.attributes.onum * (order2.attributes.c_id.attributes.price - order2.attributes.discount);
				}
				for(var i = 0; i < $scope.mid_list2.length; i++) {
					if($scope.mid_list2[i].money != 0) {
						var dd = {};
						dd.date = i + 1;
						dd.money = $scope.mid_list2[i].money;
						$rootScope.sumorder2.date_list.push(dd);
					}
				}

				//				$rootScope.sumorder2=$scope.sumorder2;
				if($rootScope.ispartners) {
					$rootScope.ispartners = false;
					location.href = "#/isloading/" + "partners2";
				}
			}, function(error) {});
		}

		$rootScope.getOrders = function() {

			var orderQuery = new AV.Query(Order);
			orderQuery.descending('createdAt');
			orderQuery.limit(10);
			orderQuery.include('shop_id'); // 关键代码，用 include 告知服务端需要返回的关联属性对应的对象的详细信息，而不仅仅是 objectId
			orderQuery.include('c_id'); // 关键代码，同上，会返回 targetAVUser 对应的对象的详细信息，而不仅仅是 objectId
			orderQuery.include('c_id.user_id');
			orderQuery.include('c_id.p_id');

			var d = new Date();
			var a = d.getFullYear();
			orderQuery.equalTo('orderyear', a);
			var b = d.getMonth() + 1;
			orderQuery.equalTo('ordermonth', b);
			var c = d.getDate();
			orderQuery.equalTo('orderday', c);

			orderQuery.equalTo('user_id', $rootScope.user);
			orderQuery.find().then(function(orders123) {
				$rootScope.orders = orders123;
			}, function(error) {});

		}

		$rootScope.getOutList = function() {

			var cProductQuery = new AV.Query(CProduct);
			cProductQuery.descending('createdAt');
			cProductQuery.include('p_id');
			cProductQuery.include('user_id');
			cProductQuery.equalTo('user_id', $rootScope.user);

			var d = new Date();
			var a = d.getFullYear();
			cProductQuery.equalTo('cpyear', a);
			var b = d.getMonth() + 1;
			cProductQuery.equalTo('cpmonth', b);
			var c = d.getDate();
			cProductQuery.equalTo('cpday', c);

			cProductQuery.find().then(function(cps) {
				$rootScope.cps = cps;
			});

			var cProductQuery = new AV.Query(CProduct);
			cProductQuery.descending('createdAt');
			cProductQuery.include('p_id');
			cProductQuery.include('user_id');
			cProductQuery.equalTo('user_id', $rootScope.user);

			var d = new Date();
			var a = d.getFullYear();
			cProductQuery.equalTo('cpyear', a);
			var b = d.getMonth() + 1;
			cProductQuery.equalTo('cpmonth', b);
			var c = d.getDate();
			cProductQuery.equalTo('cpday', c);

			cProductQuery.greaterThanOrEqualTo('snum', 1);
			cProductQuery.find().then(function(cps) {
				$rootScope.cps2 = cps;
			});
		}

		$rootScope.getProductList = function() {
			var productQuery = new AV.Query(Product);
			productQuery.descending('createdAt');
			productQuery.greaterThanOrEqualTo('pnum', 1);

			productQuery.find().then(function(ps) {
				$rootScope.ps = ps;
			});
		}

	})

	.controller('LoginCtrl', function($scope, $state, $rootScope, $window) {

		var name = localStorage.getItem("username");
		var pwd = localStorage.getItem("password");
		if(name != null) {
			log({
				username: name,
				password: pwd
			});
		}
		$scope.user = {};

		function log(user) {
			login(user).then(function(loginedUser) {
				var u = loginedUser.attributes.username;
				$rootScope.user = loginedUser;
				$rootScope.user.attributes.password = user.password;
				if(user.remember) {
					//				localStorage['c_user'] = user;
					localStorage.setItem("username", user.username);
					localStorage.setItem("password", user.password);
				}

				//调回用户
				if($rootScope.user.attributes.boss == 0) {
					$rootScope.getShopList();
					$rootScope.getPartners();
					$rootScope.getProductList();
					$rootScope.getOrders();
					$state.go("home");
				}
				if($rootScope.user.attributes.boss == 1) {
					$rootScope.getShopList();
					$rootScope.getProductList();
					$rootScope.getOrders();
					$state.go("home2");
				}

			}, function(data) {
				if(data.code == "211") {
					alert("用户名不存在");
				}
				if(data.code == "210") {
					alert("密码不对哦");
				}
			});
		}
		//
		$("#log").click(function() {
			log($scope.user);
		})

	})

	.controller('makeproductCtrl', function($scope, $rootScope) {
		$scope.mp = {};

		$("#saveproduct").click(function() {
			if($scope.mp.name == null || $scope.mp.name.length == 0) {
				alert("产品名输入错误");
			} else {
				if($scope.mp.date <= 0) {
					alert("产品保质期输入错误");
				} else {
					if($scope.mp.num <= 0) {
						alert("产品数量输入错误");
					} else {
						if($scope.mp.price <= 0) {
							alert("产品单价输入错误");
						} else {
							save_product($scope.mp);
							$rootScope.getPartners2();
							$rootScope.getShopList();
							$rootScope.getProductList();
							$rootScope.getOrders();
							location.href = "#/home2";
						}
					}
				}
			}
		});

	})

	.controller('PasswordCtrl', function($scope, $rootScope) {
		$scope.password = {};

		$("#savepassword").click(function() {
			if($scope.password.ps1 == null) {
				alert("原始密码不能为空");
			} else {
				if($scope.password.ps2 == null || $scope.password.ps3 == null) {
					alert("新密码不能为空");
				} else {
					if($scope.password.ps2 != $scope.password.ps3) {
						alert("两次密码输入不同");
					} else {
						if($scope.user.attributes.password != $scope.password.ps1) {
							alert("原始密码不对");
						} else {
							changepasswprd($rootScope.user.attributes.username, $rootScope.user.attributes.password, $scope.password.ps2, function() {
								AV.User.logOut();
								localStorage.removeItem("username");
								localStorage.removeItem("password");
								// 现在的 currentUser 是 null 了
								var currentUser = AV.User.current();
								location.href = "#/login";
							});
						}
					}
				}
			}

		})
	})

	.controller('MakeorderCtrl', function($scope, $rootScope) {

		$("#saveorder").click(function() {

			var log = 0;

			for(var i = 0; i < $rootScope.cps2.length; i++) {
				var cpp = $rootScope.cps2[i];
				if(cpp.onum != null) {
					log += 1;
				}
			}

			var log2 = 0;
			for(var i = 0; i < $rootScope.cps2.length; i++) {
				var cpp = $rootScope.cps2[i];
				var a = 0;
				if(cpp.onum == null) {
					a = 0;
				} else {
					a = cpp.onum;
				}
				if(a > cpp.attributes.snum) {
					log2 = 1;
				}
			}

			if(log > 0) {
				if(log2 == 0) {
					for(var i = 0; i < $rootScope.cps2.length; i++) {

						var cpp = $rootScope.cps2[i];
						var s = window.location.href;
						var ss = s.slice(s.length - 24, s.length);
						cpp.sid = ss;
						cpp.uid = $rootScope.user.id;
						cpp.pid = cpp.id;
						var dd = new Date();
						cpp.year = dd.getFullYear();
						cpp.month = dd.getMonth() + 1;
						cpp.day = dd.getDate();
						if(cpp.discount == null) {
							cpp.discount = 0;
						}
						if(cpp.onum != null) {
							save_cpnum(cpp.pid, cpp.attributes.snum - cpp.onum);
							save_order(cpp);
						}
					}
					$rootScope.getOutList();
					$rootScope.getPartners();
					$rootScope.getShopList();
					$rootScope.getOrders();
					$rootScope.getProductList();
					if($rootScope.user.attributes.boss == 0) {
						location.href = "#/home";
					} else {
						location.href = "#/home2";
					}
				} else {
					alert("下单量数据过大");
				}
			} else {
				alert("先填点东西吧");
			}
		})
	})

	.controller("outboundCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();
		//		$scope.c_ps=[];

		$("#save").click(function() {
			var log = 0;
			for(var i in $rootScope.ps) {
				var pp = $rootScope.ps[i];
				if(pp.tonum != null) {
					log += 1;
				}
			}

			var log2 = 0;
			for(var i = 0; i < $rootScope.ps.length; i++) {
				var pp = $rootScope.ps[i];
				var a = 0;
				if(pp.tonum == null) {
					a = 0;
				} else {
					a = pp.tonum;
				}
				if(a > pp.attributes.pnum) {
					log2 = 1;
				}
			}
			console.log(log2);

			if(log > 0) {
				if(log2 == 0) {
					for(var i in $rootScope.ps) {
						var pp = $rootScope.ps[i];
						if(pp.tonum != null) {
							pp.user_id = $rootScope.user.id;
							var dd = new Date();
							pp.year = dd.getFullYear();
							pp.month = dd.getMonth() + 1;
							pp.day = dd.getDate();
							sava_productnum(pp.id, pp.attributes.pnum - pp.tonum);
							save_cproduct(pp);
						}
					}
					$rootScope.getOrders();
					$rootScope.getOutList();
					if($rootScope.user.attributes.boss == 0) {
						$rootScope.getPartners();
						location.href = "#/home";
					} else {
						$rootScope.getPartners2();
						location.href = "#/home2";
					}
				} else {
					alert("出库量过大");
				}
			} else {
				alert("先填点东西吧");
			}
		});
	})

	.controller("InformationCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();

		$scope.userinfor = {};
		$("#saveinfor").click(function() {

			if($scope.userinfor.area == null && $scope.userinfor.area.length == 0) {

			} else {
				changearea($rootScope.user.attributes.username, $rootScope.user.attributes.password, $scope.userinfor.area);
				$rootScope.getOrders();
				$rootScope.getShopList();
				if($rootScope.user.attributes.boss == 0) {
					$rootScope.getPartners();
					location.href = "#/home";
				} else {
					$rootScope.getPartners2();
					location.href = "#/home2";
				}

			}
		});
	})

	.controller('IndexCtrl', function($scope, $rootScope) {
		$rootScope.isLogin();
		$scope.user = $rootScope.user;
		$rootScope.getOutList();
		$rootScope.getPartners();
		$rootScope.getShopList();
		$rootScope.getOrders();
		$rootScope.getProductList();
		$rootScope.getPUser(); //所有配送员
		$rootScope.getPartners2("0");
		var puserQuery = new AV.Query(PUser);
		puserQuery.descending('createdAt');
		puserQuery.find().then(function(pus) {
			for(var i = 0; i < pus.length; i++) {
				var pu = pus[i];
				if(pu.attributes.user_id == 0) {
					save_puser(pu.id, $scope.user.id, $scope.user.attributes.username);
				}
			}
		});
		//		save_puser($scope.user.id,$scope.user.attributes.username);
		$(function() {
			Qrcode.init($('[node-type=qr-btn]'));
		});
		$("#loginOut").click(function() {
			AV.User.logOut();
			localStorage.removeItem("username");
			localStorage.removeItem("password");
			// 现在的 currentUser 是 null 了
			var currentUser = AV.User.current();
			window.open("/junlebao/index.html", "_self");
		})

		function showFooterNav() {
			$("#footNav").toggle();
		}

	})

	.controller("groupbuyCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();
		$rootScope.getOutList();
		$scope.delorder = function(o) {
			for(var i = 0; i < $rootScope.cps2.length; i++) {
				var cp = $rootScope.cps2[i];
				if(o.attributes.c_id.id == cp.id) {
					save_cpnum(cp.id, cp.attributes.snum + o.attributes.onum);
					del_order(o.id);
					$rootScope.getOutList();
					$rootScope.getPartners();
					$rootScope.getShopList();
					$rootScope.getOrders();
					$rootScope.getProductList();
					location.href = "#/home";
				}
			}
		}
	})

	.controller("prodctCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();
		$scope.product = {};
		$("#save").click(function() {
			save_product($scope.product).then(function(product) {
				alert("product id:" + product.id);
			});
		});
	})

	.controller("prodctListCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();

		function update(ps) {
			$scope.apply();
		}
		productQuery.find().then(function(ps) {
			$rootScope.products = ps;
			$scope.apply(function() {
				$rootScope.products = ps;
			});
		})

	})

	.controller("registerCtrl", function($scope, $rootScope) {

		$scope.user = {};
		$scope.code = {
			flag: true,
			num: 59
		};
		$("#save").click(function() {
			Verification_Code($scope.user).then(function() {
				register().then(function(user) {
					updateRegisterUser(user, $scope.user);
					location.href = "#/login";
				});
			}, function(err) {
				alert("验证码不对！");
			})

		});

		$("#sendMobileCode").click(function() {
			//18722108478
			//15331574769
			//1000为1秒钟
			var phone = $scope.user.mobilePhoneNumber;

			$scope.$apply();
			getCode($scope.user).then(function(loginedUser) {
				$scope.code.flag = false;
				$scope.interval = setInterval(myInterval, 1000);
			}, function(error) {
				alert(error);
			})
		});

		function myInterval() {
			$scope.code.num--;
			if($scope.code.num == -1) {
				clearInterval($scope.interval);
				$scope.code.flag = true;
				$scope.code.num = 59;
			}
			$scope.$apply();
		}

	})

	.controller("findpasswordCtrl", function($scope, $rootScope) {

		$scope.user = {};
		$scope.code = {
			flag: true,
			num: 59
		};
		$("#save").click(function() {
			Verification_Code($scope.user).then(function() {
				register().then(function(user) {
					updateRegisterUser(user, $scope.user);
					location.href = "#/login";
				});
			}, function(err) {
				alert("验证码不对！");
			})

		});

		$("#findcode").click(function() {
			//18722108478
			//15331574769
			$scope.code.flag = false;
			$scope.interval = setInterval(myInterval, 1000); //1000为1秒钟
			var phone = $scope.user.mobilePhoneNumber;
			$scope.$apply();
			getCode($scope.user).then(function(loginedUser) {}, function(error) {
				alert(error);
			})
		});

		function myInterval() {
			$scope.code.num--;
			if($scope.code.num == -1) {
				clearInterval($scope.interval);
				$scope.code.flag = true;
				$scope.code.num = 59;
			}
			$scope.$apply();
		}

	})

	.controller("searchshop2Ctrl", function($scope, $rootScope) {
		$rootScope.isLogin();
	})

	.controller("searchshopCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();
		//	$scope.shops=$rootScope.shops;
		$(function() {
			var geolocation = new $.AMUI.Geolocation();
			var $myarea = $('#myarea');
			geolocation.get({
				timeout: 7000
			}).then(function(position) {
				var contentString = '你的位置：\n\t纬度 ' + position.coords.latitude +
					'，\n\t经度 ' + position.coords.longitude + '，\n\t精确度 ' +
					position.coords.accuracy;
				$myarea.html(contentString);
			}, function(err) {
				$myarea.html('获取地理位置时发生错误，错误信息：<br>' + err);
			});
		});
		$scope.showFooterNav = function() {
			$("#footNav").toggle();
		}
	})

	.controller("outdetailsCtrl", function($scope, $rootScope) {
		$rootScope.isLogin();
	})
	.controller("makeorderCtrl", function($scope, $rootScope, $stateParams) {
		$rootScope.isLogin();
	})
	.controller("makeqrcCtrl", function($scope, $rootScope, $stateParams) {
		$rootScope.isLogin();
		$scope.shoptoqrc = $stateParams.shop_id;
	})

	.controller('partnersCtrl', function($scope, $rootScope) {
		$rootScope.isLogin();
		if($rootScope.puser == null) {
			$rootScope.puser = "全部";
		}
		//		$rootScope.getPartners2("0");
		$scope.change = function(puser) {

			$rootScope.puser = puser;
			var pusers = $rootScope.pusers;
			$rootScope.ispartners = true;
			for(var i in pusers) {
				if(pusers[i].attributes.username === puser) {
					//					alert("开始");
					//					alert(pusers[i].attributes.user_id);
					$rootScope.getPartners2(pusers[i].attributes.user_id);
					//					alert("结束");
					break;
				}
			}

		}
	})

	.controller('isloading', function($scope, $rootScope, $state, $stateParams) {
		var toUrl = $stateParams.toUrl;
		$state.go(toUrl);
	})

	.controller('ordernumCtrl', function($scope, $rootScope) {
		$rootScope.isLogin();
	})

	.controller('shopmapCtrl', function($scope, $rootScope) {
		$rootScope.isLogin();

		var map = new AMap.Map("mapContainer", {
			resizeEnable: true,
			zoom: 13
		});

		map.plugin('AMap.Geolocation', function() {
			geolocation = new AMap.Geolocation({
				enableHighAccuracy: true, //是否使用高精度定位，默认:true
				timeout: 10000, //超过10秒后停止定位，默认：无穷大
				buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
				zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
				buttonPosition: 'RB'
			});
			//      map.addControl(geolocation);
			geolocation.getCurrentPosition();
			AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
			AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
		});
		//解析定位结果
		function onComplete(data) {
			var slng = data.position.getLng();
			var slat = data.position.getLat();

			shopQuery.find().then(function(shops) {
				mapinit(map, shops, slng, slat);
			})

		}
		//解析定位错误信息
		function onError(data) {
			alert("定位失败");
		}

		function mapinit(map, shops, slng, slat) {
			//	var shops=$rootScope.shopList;
			//初始化地图对象，加载地图

			var infoWindow = new AMap.InfoWindow({
				offset: new AMap.Pixel(0, -30)
			});
			for(var i = 0, marker; i < shops.length; i++) {
				var shop = shops[i].attributes;
				var marker = new AMap.Marker({
					position: [shop.lng, shop.lat],
					map: map
				});
				map_url = make_map_url(slng, slat, shop.lng, shop.lat);
				//			map_url ="javascript:js_method(mmurl)";
				var info = "商家：" + shop.name + "<br/>";
				info += "电话：" + shop.phone + "<br/>";
				info += "地址：" + shop.adress + "<br/>";
				info += "导航：<a style='color:blue' href=" + map_url + ">去这里</a><br/>";
				marker.content = info;
				marker.on('click', markerClick);
				marker.emit('click', {
					target: marker
				});
			}

			function markerClick(e) {
				infoWindow.setContent(e.target.content);
				infoWindow.open(map, e.target.getPosition());
			}
			map.setFitView();
		}

		function make_map_url(slng, slat, elng, elat) {
			//		var slng="116.478346";
			//		var slat="39.997361";
			var map_url = "http://uri.amap.com/navigation?from=";
			map_url += slng + "," + slat + ",startpoint&to=";
			map_url += elng + "," + elat + ",startpoint&";
			map_url += "mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0";
			return map_url;
		}
	})